#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/videodev2.h>
int main(int argc, char const *argv[])
{
	int fd = open("/dev/video1", O_RDWR); // 打开设备
	printf("fd %d\n", fd);



	struct v4l2_capability cap;
	ioctl(fd, VIDIOC_QUERYCAP, &cap);
	printf("DriverName: % s \nCard Name: % s \nBus info: % s \nDriverVersion: % u. % u. % u \n",
	       cap.driver,
	       cap.card,
	       cap.bus_info,
	       (cap.version >> 16) & 0xFF,
	       (cap.version >> 8) & 0xFF,
	       cap.version & 0xff);




	struct v4l2_fmtdesc fmtdesc;
	fmtdesc.index = 0;
	fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	printf("Supportformat:\n");
	while(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) != -1) {
		printf("/t%d.%s/n", fmtdesc.index + 1, fmtdesc.description);
		fmtdesc.index++;
	}


	struct v4l2_format fmt;
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	ioctl(fd, VIDIOC_G_FMT, &fmt);
	// printf("Currentdata format information:\n\twidth: %d\n\theight: %d\n", fmt.fmt.width, fmt.fmt.height);
	// struct v4l2_fmtdesc fmtdesc;
	fmtdesc.index = 0;
	fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	while(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) != -1) {
		// if(fmtdesc.pixelformat & fmt.fmt.pixelformat) {
			printf(" \tformat: % s \n", fmtdesc.description);
			// break;
		// }
		fmtdesc.index++;
	}
	close(fd);// 关闭设备
	return 0;
}
